class Student {
    //私有属性name
    private String name = "bit"; //公有属性age
    public int age = 18;
    //不带参数的构造方法
    public Student(){
        System.out.println("Student()");
    }

    private Student(String name,int age) {
        this.name = name;
        this.age = age;
        System.out.println("Student(String,name)");
    }

    private void eat(){
        System.out.println("i am eat");
    }

    public void sleep(){
        System.out.println("i am pig");
    }

    private void function(String str) {
        System.out.println(str);
    }

    @Override
    public String toString() {
            return "Student{" +
            "name='" + name + '\'' + ", age=" + age +
            '}';
    }
}

public class Test {
    public static void main(String[] args) throws ClassNotFoundException {
        //方法1： 使用forName，需要处理异常
        Class<?> stu1=Class.forName("Student");
        //Class<Student> stu1=Class.forName("Student");

        //方法2： 使用 类名.class，直接用类名访问，说明class是静态成员
        Class<?> stu2=Student.class;

        //方法3： 使用类的getClsss()方法，依赖于类对象
        Student student=new Student();
        Class<?> stu3=student.getClass();

        //说明Class<T>实例只有1份
        System.out.println(stu1==stu2); //true
        System.out.println(stu2==stu3); //true
        System.out.println(stu1==stu3); //true
    }
}
